#include<iostream>
using namespace std;
#include "Socket.hpp"
#include<time.h>    
#include<unistd.h>
#include"protocol.hpp"

int main(int argc, char* argv[])
{
    if (argc != 3)
    {
        cout << "has return " << endl;
        return 1;
    }

    string serverip = argv[1];
    uint16_t serverport = stoi(argv[1]);
    
    //未来我们客户端想要连接远端服务器， 只需要创建套接字， 然后获取套接字。 再connect连接远端服务器， 就能连接远端服务器了。
    Socket sockfd;
    sockfd.InitSocket();

    bool r = sockfd.Connect(serverip, serverport);
    if (!r)
    {
        lg(Fatal, "client conncect error, strerror: %s, errno: %d", strerror(errno), errno); 
    }
    //

    srand(time(nullptr) ^ getpid());
    int cnt = 10;
    const string opers = "+-*/%=-=&^";
    while (cnt--)
    {
        int x = rand() % 100 + 1;
        usleep(1234);
        int y = rand() % 100;
        usleep(4321);

        char oper = opers[rand() % opers.size()];
        
        Request req(x, y, oper);
        req.DebugPrint();
        string package;
        req.serialize(&package); //序列化;
        package = Encode(package);
        cout << "这是最新的发出去的请求: " << endl << package;   
    }

    sockfd.Close();
    
    return 0;
}